package com.example.demo.date;

import org.junit.Test;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.Year;

public class RiLi {

    public static void main(String[] args) {

        String weeks = "Mon Tue Wed Thu Fri Sat Sun";
        System.out.println(weeks);


        LocalDate now = LocalDate.now();
        //当月中的第几天
        int dayOfMonth = now.getDayOfMonth();

        int lengthOfMonth = now.lengthOfMonth();

        LocalDate startDate = now.minusDays(dayOfMonth - 1);

        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= lengthOfMonth; i++) {
            LocalDate localDate = startDate.plusDays(i - 1);
            DayOfWeek dayOfWeek = localDate.getDayOfWeek();
            int value = dayOfWeek.getValue();

            for (int j = 1; j <= 7; j++) {
                if (value == j) {
                    if (i < 10) {
                        sb.append(i == dayOfMonth ? i + "*  " : i + "   ");
                    } else {
                        sb.append(i == dayOfMonth ? i + "*" + " " : i + "  ");
                    }
                    break;
                } else {
                    if (i == 1) {
                        sb.append("    ");
                    }
                }
            }
            if (value == 7) {
                System.out.println(sb.toString());
                sb = new StringBuilder();
            }
        }


    }

    public void test3(){
        LocalDate now = LocalDate.now();
        int year = now.getYear();
        int dayOfYear = now.getDayOfYear();
        LocalDate start = now.minusDays(dayOfYear - 1);




    }

    @Test
    public void test1() {
        String weeks = "Mon Tue Wed Thu Fri Sat Sun";
        System.out.println(weeks);

        LocalDate now = LocalDate.now();
        int dayOfMonth = now.getDayOfMonth();
        int monthValue = now.getMonthValue();
        LocalDate localDate = now.minusDays(dayOfMonth - 1);
        DayOfWeek dayOfWeek = localDate.getDayOfWeek();
        int value = dayOfWeek.getValue();
        for (int i = 1; i < value; i++) {
            System.out.print("    ");
        }


        while (localDate.getMonthValue() == monthValue) {
            System.out.printf("%3d", localDate.getDayOfMonth());
            if (localDate.getDayOfMonth() == dayOfMonth) {
                System.out.print("*");
            } else {
                System.out.print(" ");
            }

            localDate = localDate.plusDays(1);

            if (localDate.getDayOfWeek().getValue() == 1) {
                System.out.println();
            }
        }

        if (localDate.getDayOfMonth() != 1) {
            System.out.println();
        }
    }

    @Test
    public void test2() {
        LocalDate now = LocalDate.now();
        int dayOfYear = now.getDayOfYear();
        LocalDate start = now.minusDays(dayOfYear - 1);
        Month[] values = Month.values();
        for (Month value : values) {
            String weeks = "Mon Tue Wed Thu Fri Sat Sun";
            System.out.println(weeks);
            DayOfWeek dayOfWeek = start.getDayOfWeek();
            int weekValue = dayOfWeek.getValue();
            for (int i = 1; i < weekValue; i++) {
                System.out.print("    ");
            }
            while (start.getMonthValue() == value.getValue()) {
                System.out.printf("%3d", start.getDayOfMonth());

                if (start.getDayOfYear() == dayOfYear) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");
                }
                start = start.plusDays(1);
                if (start.getDayOfWeek().getValue() == 1) {
                    System.out.println();
                }
            }
            if (start.getDayOfWeek().getValue() != 1) {
                System.out.println();
            }
            System.out.println();
        }
    }
}
